package com.sdkx.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sdkx.app.R;
import com.sdkx.app.activitys.RoutesInfo;
import com.sdkx.app.entity.CustomAirPort;
import com.sdkx.app.entity.CustomWayPoint;

import java.util.List;

public class RouteInfoAdapter extends BaseAdapter {
    private Context context;
    private List<Object> list;

    public RouteInfoAdapter(Context context, List<Object> list) {
          this.context=context;
          this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView =  View.inflate(context, R.layout.routeinfo_item, null);
            holder = new ViewHolder();
            holder.tv_point_name = (TextView) convertView.findViewById(R.id.tv_point_name);
            holder.tv_point_jingdu = (TextView) convertView.findViewById(R.id.tv_point_jingdu);
            holder.tv_point_weidu = (TextView) convertView.findViewById(R.id.tv_point_weidu);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
      Object temp= list.get(position);
        if(temp instanceof CustomWayPoint){
            holder.tv_point_name.setText( ((CustomWayPoint)temp).getName());
            holder.tv_point_weidu.setText( ((CustomWayPoint)temp).getLatitude()+"");
            holder.tv_point_jingdu.setText( ((CustomWayPoint)temp).getLongitude()+"");
        }else  if(temp instanceof CustomAirPort){
            holder.tv_point_name.setText( ((CustomAirPort)temp).getName());
            holder.tv_point_weidu.setText( ((CustomAirPort)temp).getLatitude()+"");
            holder.tv_point_jingdu.setText( ((CustomAirPort)temp).getLongitude()+"");
        }
        return convertView;
    }

    static class ViewHolder{
        public TextView tv_point_name;
        public TextView tv_point_jingdu;
        public TextView tv_point_weidu;
    }
}
